// 扩展1-1 函数后面的const
/**
 * 参考链接: https://blog.csdn.net/SMF0504/article/details/52311207
 * 总结：
 *  1. 非成员函数和类静态成员函数
 *  2. const 成员函数不能修改成员，表示的是成员隐含参数this，是const 指针。 唯一例外是 可以修改 mutable修饰的成员变量值,使用场景如：const 成员函数调用计数
 *  3. const 成员函数内只能调用const版本的成员函数，非const成员函数 都可以调。
 * 
*/
#include <iostream>
class Test
{
private:
  int a;
  mutable int b;
  mutable int num;

public:
  // error: static member function 'static void Test::fun1()' cannot have cv-qualifier
  Test() : num(0) {}
  static void fun1()
  {
    std::cout << "fun1()..." << std::endl;
  }

  void fun2() const
  {
    std::cout << "fun2()..." << std::endl;
  }

  void fun3() const
  {
    // this->a = 0; // error: assignment of member 'Test::a' in read-only object
    std::cout << "fun3()..." << std::endl;
  }

  void fun4()
  {
    this->a = 0;
    std::cout << "fun4()..." << std::endl;
  }

  void fun5() const
  {
    std::cout << "fun5()..." << std::endl;
    // this->fun4(); // error: passing 'const Test' as 'this' argument discards qualifiers [-fpermissive]
  }

  // const 成员函数调用修改 mutable 成员
  void fun6() const
  {
    std::cout << "fun6()..." << std::endl;
    this->b = 6;
    std::cout << "b : " << b << std::endl;
  }

  // mutable是用来修饰变量的
  // void fun7() mutable
  // {
  //   std::cout << "fun7()..." << std::endl;
  //   this->b = 7;
  //   std::cout << "b : " << b << std::endl
  // }

  void fun8() const
  {
    std::cout << "fun8()..." << std::endl;
    std::cout << "num : " << num << std::endl;
    this->num++;
    // num++;
  }
};
void fun1();
int main(void)
{
  // fun1();
  Test t1;
  t1.fun2();
  t1.fun4();
  t1.fun6();
  t1.fun8();
  t1.fun8();
  t1.fun8();
  printf("-------------------end---------------------\n");
  return 0;
}

// error: non-member function 'void fun1()' cannot have cv-qualifier
// void fun1() const
void fun1()
{
  std::cout << "fun1()..." << std::endl;
}